
function SetCameraState(a)
{
//	var setArray=new Array("set0","set1","set2","set3","set4","set5","set6","set7","set8" );
//	var setTitle=new Array("title0","title1","title2","title3","title4","title5","title6","title7","title8");
	flashpoint();

	printf('# API: SetCameraState(PName, value ) ');
	printf('# Sets the state of the camera ');
	printf('# and verifies the setting by calling GetCameraState()');
	printf(' ' );
	printf('# OUTPUT FORMAT: ');
	printf('# PName [status] set-value (case) get-value ');
	printf('# status is from SetCameraState() ');
	printf('# set-value is the value used in SetCameraState() ');
	printf('# (case) could be default, min, max or others ');
	printf('# get-value is the value returned by GetCameraState() ');
	printf('# set-value should equal get-value' );

	var usetVar=new Array("uset0","uset1","uset2","uset3","uset4","uset5","uset6","uset7" );
	var isetVar=new Array("iset0","iset1","iset2","iset3","iset4","iset5","iset6","iset7" );
	var ssetVar=new Array("sset0","sset1","sset2","sset3","sset4","sset5","sset6","sset7" );
	
	var setTitle=new Array("title0","title1","title2","title3","title4","title5","title6","title7" );

	var i,setting;
	
	writeMenu('"SetCameraState"','"CMD"','"SetCameraState()"');
	writeVariables();
	printf('declare s: readwrite ');

	print('declare u: uset0');
	for(i=1 ;i< usetVar.length ; i++) print(",",usetVar[i]); printf(' ');
	print('declare i: iset0');
	for(i=1 ;i< isetVar.length ; i++) print(",",isetVar[i]); printf(' ');
	print('declare s: sset0');
	for(i=1 ;i< ssetVar.length ; i++) print(",",ssetVar[i]); printf(' ');

	print('declare s: title0');	
	for(i=1 ;i< setTitle.length ; i++) print(",",setTitle[i]); printf(' ');

	printf('declare u: doit,countSetting');
	
	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZSState.txt"');
	writeFileOpen();
	
	printf('WriteLine(fd," ")');
	printf('WriteLine(fd," API: SetCameraState(PName, value ) ")');
	printf('WriteLine(fd,"  Sets the state of the camera ")');
	printf('WriteLine(fd,"  and verifies the setting by calling GetCameraState()")');
	printf('WriteLine(fd,"  ")' );
	printf('WriteLine(fd,"  OUTPUT FORMAT: ")');
	printf('WriteLine(fd,"  PName [status] set-value (case) get-value ")');
	printf('WriteLine(fd,"  status is from SetCameraState() ")');
	printf('WriteLine(fd,"  set-value is the value used in SetCameraState() ")');
	printf('WriteLine(fd,"  (case) could be default, min, max or others ")');
	printf('WriteLine(fd,"  get-value is the value returned by GetCameraState() ")');
	printf('WriteLine(fd,"  set-value should equal get-value")' );
	printf('WriteLine(fd," ")');

		printf('count=1');
		printf('LOOP:');
		printf('doit=0');
		printf('theType="UInt"');
		printf('umin=0');
		printf('umax=0');
		printf('countSetting=0');
		for( i=1 ; i< a.length ; i++)
		{ 			

 		// only can change a RW parameter 
 		if( a[i].host != "Write" ){
 				printf(" ");
 				printf('if count == ',i );
 				printf('WriteLine(fd," ")' );
				printf('WriteLine(fd,"**** ',a[i].desc,' ****" )' );
 				printf('WriteLine(fd,count,','")",',a[i].param,'," is READ only *************" )' );
 				printf('end');
 		 		continue;
 		}	
 	 			printf(" ");
 				printf('if count == ', i );
  	 			printf("doit=1");
  	 			printf('param=',a[i].param);
  	 			printf(setTitle[0],'="',a[i].desc,'"');
  	 			
  	 			// write theType									
 				if( a[i].type == "String" || a[i].type=="DosName")
 					printf('theType="String"','<br>',"sdefault = ",a[i].def);
 				else if( (a[i].type=="Enum List") || (a[i].type=="UInt") )
 					printf("udefault = ",a[i].def);
 				else if( a[i].type=="SInt" )
 					printf('theType="SInt"','<br>',"default = ",a[i].def); 					
 				else 
 					printf('theType="Hex"','<br>',"udefault = ",a[i].def); 					

// 	else if( (a[i].type=="Enum List Hex") || (a[i].type=="Hex") || (a[i].type=="Fixed") || (a[i].type=="BitMask") )
 					
 				
 				// minimum, maximum range for either unsigned int, or signed int
 				// if this is a string, then it is a (max) hexadecimal value
				// if max is non-zero then there  min-max values are present
				// otherwise a zero indicates that there are no min-max values
				// if the 2nd clause is executed on a string, Netscape 3 complains
 				if (  (typeof(a[i].max)=="string") || (a[i].max != 0 )  )
 				if( (a[i].type=="Enum List") || (a[i].type=="Enum List Hex") || (a[i].type=="UInt") || (a[i].type=="Fixed")){
 							printf("umin=",a[i].min );
 							printf("umax=",a[i].max );
 				}
 				else if( a[i].type=="SInt" ){
 							printf("min=",a[i].min );
 							printf("max=",a[i].max );
 				}
   				setting=1;								
 				for( theType in  a[i]   ){	
 				 		// paramNotThere(param, theObject  ) defined in GetCapabilities.js
 						// tag is a global object (defined via a function)
 						// that contains tags common to all parameters
						// this code picks up the extra tags which are NOT defined in tag
						// typically these are min,max, default or other  settings
						// the title is taken from the tag name itself!
						if( paramNotThere( theType , parameterTag) ){	
								printf( setTitle[setting]," = ",'"',theType ,'"' );

								// select the right variable type
 								if( a[i].type == "String" || a[i].type=="DosName")
 									printf( ssetVar[setting]," = ",a[i][theType] );
					 			else if( a[i].type=="SInt" )
				 					printf( isetVar[setting]," = ",a[i][theType] ); 				
 					 			else 
					 				printf( usetVar[setting]," = ",a[i][theType] );					

							setting = setting + 1;
							}
				}

				printf('countSetting=',setting-1);
 				printf('end '); 			

				
		}// end of this HUGE for loop
		printf(' ');
		
// start to examine SetCameraState()
	printf('Wait(100)');
	printf('if doit == 0');
	printf('count=count+1 ');	
	printf('goto LOOP');
	printf('end');
	printf(' ');
	
	printf('WriteLine(fd," ")' );
	printf('WriteLine(fd,"**** ",',setTitle[0],'," ****" )' );

	printf(' if theType=="SInt"');
	printf(' goto case_SINT');
	printf(' end','<br>');

	printf(' if theType=="String"');
	printf(' goto case_STRING');
	printf(' end','<br>');
	
	printf(' ' );
	printf('CASE_UINT:');
	printf('status=SetCameraState(param,udefault)' );
	printf('status1=GetCameraState(param,uvar)' );
	printf('if theType != "Hex" ');
	printf('DisplayLine(count,")",param,"[",status,"] " , udefault ," (def)")' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , udefault," (default)"," (",uvar,")" )' );	
	printf('end','<br>');
	
	printf('if theType == "Hex" ');
	printf('bdefault=udefault');
	printf('bvar=uvar');
	printf('DisplayLine(count,")",param,"[",status,"] " , bdefault ," (def)")' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , bdefault," (default)"," (",bvar,")" )' );	
	printf('end','<br>');
	
	printf('<br>','if udefault != uvar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');		
	printf(' WriteLine(fd," ***??? ERROR ??? *** ") ');
	printf(' end ','<br>');
	
	
	printf('<br>','if umax == 0 ' );
	printf('goto UINT_MINMAX_END');
	printf('end ');
	
	printf('status=SetCameraState(param,umin)' );
	printf('status1=GetCameraState(param,uvar)' );	
	
//	printf('WriteLine(fd,"-------")');
	printf('if theType != "Hex" ');
	printf('DisplayLine(count,")",param,"[",status,"] " , umin," (min)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , umin," (min) (",umin,")" )' );
	printf('end');
	printf('if theType == "Hex" ');
	printf('bmin=umin ');
	printf('bvar=uvar ');	
	printf('DisplayLine(count,")",param,"[",status,"] " , bmin," (min)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , bmin," (min) (",bvar,")" )' );
	printf('end');
	
	printf('<br>','if umin != uvar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');	
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');
	
	
	printf(' ');
	printf('status=SetCameraState(param,umax)' );
	printf('status1=GetCameraState(param,uvar)' );
	printf(' if theType!="Hex"');	
	printf('DisplayLine(count,")",param,"[",status,"] " , umax," (max)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , umax," (max) (",umax,")" )' );
	printf('end');
	printf(' if theType=="Hex"');
	printf('bmax=umax');	
	printf('DisplayLine(count,")",param,"[",status,"] " , bmax," (max)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , bmax," (max) (",bmax,")" )' );
	printf('end');		
	
	printf('<br>','if umax != uvar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');	
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');
	
	printf(' UINT_MINMAX_END: ');
	printf('# end of min,max stuff ');
// end of min, max stuff

//# **********CUT HERE ****************************************************
	for( n=1 ; n<=5 ; n++){
			
	printf(' if countSetting>=',n);
	printf(' status=SetCameraState(param,',usetVar[n],')');
	printf(' status1=GetCameraState(param,uvar)  ');

	printf(' if theType!="Hex"');		
	printf(' DisplayLine(count,")",param,"[",status,"] " ,', usetVar[n] ,'," (",',setTitle[n],',")" ) ');
	printf(' WriteLine(fd,count,")",param,"[",status,"] " ,', usetVar[n] ,'," (",',setTitle[n],',") (", uvar,")") ');
	printf('end');
	printf(' if theType=="Hex"');	
	printf(' bvar=uvar');
	printf(' bvar1=',usetVar[n] );
	printf(' DisplayLine(count,")",param,"[",status,"] " ,bvar1," (",',setTitle[n],',")" ) ');
	printf(' WriteLine(fd,count,")",param,"[",status,"] " ,bvar1," (",',setTitle[n],',")  (", bvar,")") ');
	printf('end');

	printf(' if ',usetVar[n],'!= uvar');
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ")  ');
	printf(' end  ');
	printf(' end <br>');
	
	}

//# **********CUT HERE ****************************************************

	printf('# SET TO DEFAULT ');
	printf('status=SetCameraState(param,udefault)' );
	printf(' ');

	printf('goto CONTINUE');
	printf('# UINT finished  **************************************************');		


	printf('case_STRING:');
	printf('status=SetCameraState(param,sdefault)' );
	printf('status1=GetCameraState(param,svar)' );

	printf('DisplayLine(count,")",param,"[",status,"] " , sdefault ," (def)")' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , sdefault," (default)"," (",svar,")" )' );	

	printf('<br>','if sdefault != svar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');	
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');

//# **********CUT HERE ****************************************************
	for( n=1 ; n<=5 ; n++){
			
	printf(' if countSetting>=',n);
	printf(' status=SetCameraState(param,',ssetVar[n],')');
	printf(' status1=GetCameraState(param,svar)  ');

	printf(' DisplayLine(count,")",param,"[",status,"] " ,', ssetVar[n] ,'," (",',setTitle[n],',")" ) ');
	printf(' WriteLine(fd,count,")",param,"[",status,"] " ,', ssetVar[n] ,'," (",',setTitle[n],',") (", svar,")") ');

	printf(' if ',ssetVar[n],'!= svar');
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ")  ');
	printf(' end  ');
	printf(' end <br>');
	
	}

//# **********CUT HERE ****************************************************

	
	printf('goto CONTINUE');
	printf('# STRING finished  ************************************************');		
	
	printf('case_SINT:');
	printf('status=SetCameraState(param,default)' );
	printf('status=GetCameraState(param,ivar)' );

	printf('DisplayLine(count,")",param,"[",status,"] " , default ,"(def)")' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , default,"( default )"," (",ivar,")" )' );	
	
	printf('<br>','if default != ivar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');		
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');
		
	printf('<br>','if max != 0 ' );
	printf('status=SetCameraState(param,min)' );
	printf('status=GetCameraState(param,ivar)' );	
	
	printf('DisplayLine(count,")",param,"[",status,"] " , min," (min)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , min," (min) (",ivar,")" )' );

	
	printf('<br>','if min != ivar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');	
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');
	
	
	printf(' ');
	printf('status=SetCameraState(param,max)' );
	printf('status=GetCameraState(param,ivar)' );

	printf('DisplayLine(count,")",param,"[",status,"] " , max," (max)" )' );
	printf('WriteLine(fd,count,")",param,"[",status,"] " , max," (max) (",ivar,")" )' );

	
	printf('<br>','if max != ivar');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');	
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');
	printf(' end ');
	printf('# end of min,max stuff ');
// end of min, max stuff

//# **********CUT HERE ****************************************************
	for( n=1 ; n<=5 ; n++){
			
	printf(' if countSetting>=',n);
	printf(' status=SetCameraState(param,',isetVar[n],')');
	printf(' status=GetCameraState(param,ivar)  ');

	printf(' DisplayLine(count,")",param,"[",status,"] " ,', isetVar[n] ,'," (",',setTitle[n],',")" ) ');
	printf(' WriteLine(fd,count,")",param,"[",status,"] " ,', isetVar[n] ,'," (",',setTitle[n],',")  (", ivar,")") ');

	printf(' if ',isetVar[n],'!= ivar');
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ")  ');
	printf(' end  ');
	printf(' end <br>');
	
	}

//# **********CUT HERE ****************************************************

	printf('# SET TO DEFAULT ');
	printf('status=SetCameraState(param,idefault)' );
	printf(' ');

	printf('SetCameraState(param,idefault)' );
	printf('  ');

	printf('goto CONTINUE');

	printf('# HEX finished  ***************************************************');		

	printf('CONTINUE:');
	printf(' ');
	printf('if count<', a.length-1 );
	printf('count=count+1 ');
	printf('goto LOOP');
	printf('end');
	
	writeFileClose();
	printf('exitscript');

}

